package com.yangrong.newsservice.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yangrong.newsservice.entity.TbArticleLabelEntity;
import com.yangrong.newsservice.service.TbArticleLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yangrong.common.utils.PageUtils;
import com.yangrong.common.utils.R;


/**
 * 文章标签表
 *
 * @author yangrong
 * @email 455833224@qq.com
 * @date 2020-09-08 11:03:19
 */
@RestController
@RequestMapping("article/tbarticlelabel")
public class TbArticleLabelController {
    @Autowired
    private TbArticleLabelService tbArticleLabelService;

    /**
     * getAllLabelList
     */
    @RequestMapping("/getAllLabelList")
    public R getAllLabelList() {
        List<Map<String, Object>> data = tbArticleLabelService.getAllLabelList();

        return R.ok().put("labelList", data);
    }

    /**
     * 获取首页文章标签TagList
     * @return
     */
    @RequestMapping("/getTagList")
    public R getTagList() {
        List<Map<String, Object>> data = tbArticleLabelService.getTagList();

        return R.ok().put("tagList", data);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tbArticleLabelService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TbArticleLabelEntity tbArticleLabel = tbArticleLabelService.getById(id);

        return R.ok().put("tbArticleLabel", tbArticleLabel);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbArticleLabelEntity tbArticleLabel) {
        tbArticleLabelService.save(tbArticleLabel);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbArticleLabelEntity tbArticleLabel) {
        tbArticleLabelService.updateById(tbArticleLabel);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        tbArticleLabelService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
